package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.SubwayLineBean;
import sz.szsmk.citizencard.widget.TransMarkUtils;

public class SubwaySitelistAdapter extends RecyclerView.Adapter<SubwaySitelistAdapter.ItemHolder> {

    private Context context;

    List<SubwayLineBean.LineListBean.GBean> data = new ArrayList<>();
//    List<BusLineResult.BusStation> busStationList = new ArrayList<>();
    int currentLine;

    ISubwaySiteListClickListener iSubwaySiteListClickListener;
    public SubwaySitelistAdapter(Context context ) {
        this.context = context;
    }

    @Override
    public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_classify_morelist, parent, false);
        return new ItemHolder(view);
    }

    @Override
    public void onBindViewHolder(ItemHolder holder, int position) {

        holder.txt.setText(data.get(position).getA());
        holder.txt.setTextColor(0xFF666666);
        holder.site.setVisibility(View.GONE);
        String siteTv = data.get(position).getA();

        TransMarkUtils.setTransMark(siteTv, holder.site, currentLine, context);
        holder.itemView.setOnClickListener(v -> {
            if(iSubwaySiteListClickListener!=null){
                iSubwaySiteListClickListener.onClick(data.get(position));
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public void setBusStationList(List<SubwayLineBean.LineListBean.GBean> data,int currentLine) {
        this.data.clear();
        this.currentLine = currentLine;
        this.data.addAll(data);
        notifyDataSetChanged();
    }

    public static class ItemHolder  extends RecyclerView.ViewHolder {
        TextView txt;
        TextView site;

        public ItemHolder(View view) {
            super(view);
            txt = (TextView) view.findViewById(R.id.moreitem_txt);
            site = (TextView) view.findViewById(R.id.mainitem_img);
        }
    }


    public interface ISubwaySiteListClickListener{
        void onClick(SubwayLineBean.LineListBean.GBean busStation);
    }

    public void setiSubwaySiteListClickListener(ISubwaySiteListClickListener iSubwaySiteListClickListener) {
        this.iSubwaySiteListClickListener = iSubwaySiteListClickListener;
    }
}
